home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / zendisk2.zip / LST14-4.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  1KB  |  47 lines

  1. ;
  2. ; *** Listing 14-4 ***
  3. ;
  4. ; Copies the standard input to the standard output,
  5. ; converting all characters to uppercase. Does so
  6. ; one character at a time.
  7. ;
  8.     jmp    Skip
  9. ; Storage for the character we're processing.
  10. Character    db    ?
  11. ErrorMsg    db    'An error occurred', 0dh, 0ah
  12. ERROR_MSG_LENGTH equ    $-ErrorMsg
  13. ;
  14. Skip:
  15.     call    ZTimerOn
  16. CopyLoop:
  17.     mov    ah,3fh    ;DOS read fn
  18.     sub    bx,bx    ;handle 0 is the standard input
  19.     mov    cx,1    ;we want to get 1 character
  20.     mov    dx,offset Character ;the character goes here
  21.     int    21h    ;get the character
  22.     jc    Error    ;check for an error
  23.     and    ax,ax    ;did we read any characters?
  24.     jz    Done    ;no, we've hit the end of the file
  25.     mov    al,[Character]    ;get the character and
  26.     cmp    al,'a'        ; convert it to uppercase
  27.     jb    WriteCharacter    ; if it's lowercase
  28.     cmp    al,'z'
  29.     ja    WriteCharacter
  30.     and    al,not 20h    ;it's uppercase-convert to
  31.     mov    [Character],al    ; uppercase and save
  32. WriteCharacter:
  33.     mov    ah,40h    ;DOS write fn
  34.     mov    bx,1    ;handle 1 is the standard output
  35.     mov    cx,1    ;we want to write 1 character
  36.     mov    dx,offset Character ;the character to write
  37.     int    21h    ;write the character
  38.     jnc    CopyLoop ;if no error, do the next character
  39. Error:
  40.     mov    ah,40h    ;DOS write fn
  41.     mov    bx,2    ;handle 2 is standard error
  42.     mov    cx,ERROR_MSG_LENGTH ;# of chars to display
  43.     mov    dx,offset ErrorMsg ;error msg to display
  44.     int    21h    ;notify of error
  45. Done:
  46.     call    ZTimerOff
  47.